package com.winchain.chainbill.bill.biz.contract.cmd;

import com.shell.bee.base.exception.UnCheckMsgException;
import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.esign.po.EsCust;
import com.shell.bee.esign.service.EsCustService;
import com.shell.bee.esign.service.EsignSignService;
import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICommand;
import com.shell.framework.utils.CommonDataUtil;
import com.timevale.esign.sdk.tech.bean.result.Result;
import com.winchain.chainbill.bill.biz.Bill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class EsignGetPhoneCodeCmd<T> implements ICommand<Bill<T>> {
	@Autowired
	private EsCustService esCustService;
	@Autowired
	private EsignSignService esignSignService;

	public boolean execute(CommandContext<Bill<T>> context) throws Exception {
		String userId = CommonDataUtil.getUserId();
		EsCust esCust = (EsCust) this.esCustService.selectByKey(userId);
		if ((esCust == null) || (StringUtil.emptyAndNull(esCust.getAcctId()))) {
			throw new UnCheckMsgException("������e������������");
		}
		Result result = this.esignSignService.getMobileCode(esCust.getAcctId(), esCust.getMobile());
		if (result.getErrCode() != 0) {
			throw new UnCheckMsgException("��������������������" + result.getMsg());
		}
		return false;
	}
}
